package me.jollyfly.jshop.web.portal.service.impl

import me.jollyfly.jshop.content.client.feign.ContentClient
import me.jollyfly.jshop.item.client.feign.ItemClient
import me.jollyfly.jshop.web.portal.service.IndexService
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import java.util.*

/**
 * 网站门户首页业务类，从商品微服务，内容管理微服务获取信息
 * @author jollyfly
 */
@Service
class IndexServiceImpl : IndexService {

    @Autowired
    private val itemClient: ItemClient? = null

    @Autowired
    private val contentClient: ContentClient? = null


    /**
     * 加载首页所需数据：1.所有的一级类目  2.滚动广告位内容   3. 中部广告位内容
     * @return Map
     * *
     * @author: jollyfly
     * *
     * @version 1.0.0
     */
    override fun loadIndexData(): Map<String, Any> {
        val data: MutableMap<String, Any> = HashMap()
        val categoryList = itemClient!!.listCategory().data
        val sliderAds = contentClient!!.listSliders().data
        val recommendationList = contentClient.listRecommendation().data
        data.put("sliderAds",sliderAds!!)
        data.put("categoryList", categoryList!!)
        data.put("recommendationList",recommendationList!!)
        return data

    }

    companion object {

        private val logger = LoggerFactory.getLogger(IndexServiceImpl::class.java)
    }
}
